package wheel;

import wheel.Game.ContestantAction;

public class EagerSolver extends Computer {

	public EagerSolver(String name, boolean debugMode, int perWordPossibilityThreshold) {
		super(name, debugMode);
		this.perWordPossibilityThreshold = perWordPossibilityThreshold;
	}

	public ContestantAction getContestantAction() {
		// Before taking any actions, the Computer will update its information.
		prepareToSolve();
		
		// The EagerSolver will always check to see if solving might be fruitful
	
		if (!formulateSolution().equals(NO_SOLUTION)) {
			System.out.println(Computer.SOLVE);
			return Game.ContestantAction.SOLVE;
		}
		else {
			// I have no solution, must resort to picking consonants
			if (this.currentPuzzle.isMoreConsonants()) {
				System.out.println(Computer.SPIN);
				return Game.ContestantAction.SPIN_WHEEL;
			}
			else {
				if (this.currentPuzzle.isMoreVowels() && this.getWinnings() >= 250) {
					System.out.println(Computer.VOWEL);
					return Game.ContestantAction.BUY_VOWEL;
				}
				else {
					// No more consonants, and not enough money to buy vowel....in trouble!
					return Game.ContestantAction.WAVE_TO_VANNA;  // Nothing else to do
				}
			}			
		}
	}
	
	
	
	@Override
	public ContestantAction getFreePlayAction() {
		if (!formulateSolution().equals(NO_SOLUTION)) {
			if (this.currentPuzzle.isMoreVowels()) {
				System.out.println("I will take a free vowel.");
				return Game.ContestantAction.FREE_VOWEL;
			}
			else {
				System.out.println("I will take a free consonant.");
				return Game.ContestantAction.FREE_CONSONANT;
			}
		}
		else {
			System.out.println("I would like a free chance to solve the puzzle.");
			return Game.ContestantAction.FREE_GUESS;
		}
	}
	
	public void speak() {
		SoundPlayer audio = new SoundPlayer();
		switch (1 + (int)(Math.random() * 3)) {
		case 1:
			audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "HAL.wav");
			break;
		case 2:
			audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "HAL2.wav");
			break;
		case 3:
			audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "HAL3.wav");
			break;
		}
		
	}

	@Override
	public void learnPuzzle(Puzzle puzzle) {
		// EagerSolver doesn't learn.
		return;
	}
}
